package com.aigc.sclassroom.controller;

import com.aigc.sclassroom.pojo.Result;
import com.aigc.sclassroom.pojo.Sign;
import com.aigc.sclassroom.pojo.SignRecord;
import com.aigc.sclassroom.service.SignService;
import org.jetbrains.annotations.TestOnly;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sign")
public class SignController {

    @Autowired
    private SignService signService;

    /**
     * 开始创建签名
     *
     * @param classId 班级ID
     * @param duration 签名持续时间（单位：分钟）
     * @return ResponseEntity 包含创建的签名信息的响应实体
     */
    @PostMapping("/start")
    public ResponseEntity<Sign> startSign(@RequestParam Long classId, @RequestParam Integer duration) {
        return ResponseEntity.ok(signService.createSign(classId, duration));
    }

    /**
     * 提交签名
     *
     * @param signId 签名ID
     * @param userId 用户ID
     * @param code 验证码
     * @return ResponseEntity对象，包含操作结果
     */
    @PostMapping("/submit")
    public ResponseEntity<?> submitSign(@RequestParam Long signId, @RequestParam Long userId, @RequestParam String code) {
        try {
            signService.studentSign(signId, userId, code);
        return ResponseEntity.ok().build();
        } catch (RuntimeException ex) {
            return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST);
        }
    }

    /**
     * 获取签名状态
     *
     * @param signId 签名ID
     * @return ResponseEntity<Map<String, Object>> 包含签名状态的响应实体
     */
    @GetMapping("/status/{signId}")
    public ResponseEntity<Map<String, Object>> getStatus(@PathVariable Long signId) {
        return ResponseEntity.ok(signService.getSignStatus(signId));
    }


}